package org.shock.ss.sms.action.system;

import java.util.ArrayList;
import java.util.List;

import org.shock.ss.sms.commons.db.DbTools;
import org.shock.ss.sms.commons.utils.JsonUtil;
import org.shock.ss.sms.service.system.PortalService;
import org.shock.ss.sms.service.system.impl.PortalServiceImpl;
import org.shock.ss.sms.bean.system.Portal;
import org.shock.ss.sms.commons.dao.DaoFactory;
import org.shock.ss.sms.dao.system.impl.PortalDaoImpl;
import org.shock.ss.sms.action.BaseAction;

public class PortalAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;
	/** 获得service */
	private PortalService ps = new PortalServiceImpl((PortalDaoImpl) DaoFactory.getDao("PortalDao"));
	private Portal portal = new Portal();
	private List list = new ArrayList();
	private String items;
	private Long fid;// 论坛版块id
	private String ndjf;// 年度总分
	private String wcl;// 任务完成率
	private float zf;// 年度积分
	private String lsjf;// 历史积分
	private String ygzt;// 员工状态
	private String kslx;// 考试类型

	/**
	 * 任务提醒
	 * 
	 * @return
	 * @throws Exception
	 */
	public String rwtx() throws Exception {
		return SUCCESS;
	}

	/**
	 * 论坛版块最新主题
	 * 
	 * 典型案例
	 * 
	 * 执法交流
	 * 
	 * @return
	 * @throws Exception
	 */
	public String recentTopicList() throws Exception {
		String sql = "SELECT * FROM ( " + "SELECT t.*, p.user_id AS last_user_id, p.post_time, p.attach AS attach, "
				+ " ROW_NUMBER() OVER(ORDER BY topic_type DESC, topic_last_post_id DESC) - 1 LINENUM"
				+ " FROM jforum_topics t, jforum_posts p " + " WHERE p.post_id = t.topic_last_post_id "
				+ "AND p.need_moderate = 0 AND p.forum_id=" + fid + " ) " + "WHERE LINENUM < 5";
		// System.out.println(sql);
		list = DbTools.getMapsInList(sql);
		return SUCCESS;
	}

	/**
	 * 积分排名
	 * 
	 * @return
	 */
	public String jfpm() {

		return SUCCESS;
	}

	public String savePortal() throws Exception {
		// System.out.println(getUserInfor().getId());
		ps.save(getUserInfor().getId(), JsonUtil.String2List(items, Portal.class));
		if ("ajax".equals(op)) {
			return "ajxsuccess";
		}

		return SUCCESS;
	}

	public String addPortal() throws Exception {
		if (action.equals("before")) {// 显示添加页面
			return "before";
		}
		ps.add(portal);
		message = "添加成功！";
		return SUCCESS;
	}

	public String updatePortal() throws Exception {
		if (action.equals("before")) {// 显示添加页面
			return "before";
		}
		ps.update(portal);
		return SUCCESS;
	}

	public Portal getPortal() {
		return portal;
	}

	public void setPortal(Portal portal) {
		this.portal = portal;
	}

	public List getList() {
		return list;
	}

	public void setList(List list) {
		this.list = list;
	}

	public String getItems() {
		return items;
	}

	public void setItems(String items) {
		this.items = items;
	}

	/**
	 * @return the fid
	 */
	public Long getFid() {
		return fid;
	}

	/**
	 * @param fid
	 *            the fid to set
	 */
	public void setFid(Long fid) {
		this.fid = fid;
	}

	public String getNdjf() {
		return ndjf;
	}

	public void setNdjf(String ndjf) {
		this.ndjf = ndjf;
	}

	public String getWcl() {
		return wcl;
	}

	public void setWcl(String wcl) {
		this.wcl = wcl;
	}

	public float getZf() {
		return zf;
	}

	public void setZf(float zf) {
		this.zf = zf;
	}

	public String getLsjf() {
		return lsjf;
	}

	public void setLsjf(String lsjf) {
		this.lsjf = lsjf;
	}

	public String getYgzt() {
		return ygzt;
	}

	public void setYgzt(String ygzt) {
		this.ygzt = ygzt;
	}

	public String getKslx() {
		return kslx;
	}

	public void setKslx(String kslx) {
		this.kslx = kslx;
	}

}
